<?php
/**
 * This file is part of php-server-class.
 * 
 * php-server-class is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * php-server-class is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with php-server-class.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @package php-server-class
 * @author Rick Barenthin <dunst0@gmail.com>
 * @copyright Copyright (c) 2010, Rick Barenthin
 * @license http://www.gnu.org/licenses/ GNU General Public License v3
 * @version 0.0.4
 */
declare(encoding='UTF-8');
namespace Server;


/**
 * Server Interface
 *
 * @since Version 0.0.1
 */
interface IServer
{
    /** Default Host IP */
    const HOST = '127.0.0.1';
    /** Default Port */
    const PORT = 80;
    
    /** Default Log Pfad */
    const LOG_PATH = '';
    /** Default Access Log Pfad */
    const ACCESS_LOG_PATH = '';
    
    /** Log Format */
    const LOG_FORMAT = '[%s] :: [%s] "%s"';
    /** Log Datums Format */
    const LOG_DATE_FORMAT = 'r';
    
    /** Log Type Debug */
    const L_DEBUG = 'Debug';
    /** Log Type Message */
    const L_MESSAGE = 'Message';
    /** Log Type Notice */
    const L_NOTICE = 'Notice';
    /** Log Type Warning */
    const L_WARNING = 'Warning';
    /** Log Type Exception */
    const L_EXCEPTION = 'Exception';
    
    /** Access Log Format */
    const ACCESS_LOG_FORMAT = '[%s] %s %s';
    /** Access Log Datums Format */
    const ACCESS_LOG_DATE_FORMAT = 'r';
    
    /** IP Pattern */
    const IP_PATTERN = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';
    
    
    /**
     * Klassen Konstruktor
     * 
     * @since Version 0.0.1
     * @param string $host Hostname oder IP
     * @param integer $port Portnummer
     * @param string $logPath Log Pfad
     */
    public function __construct ($host = IServer::HOST, $port = IServer::PORT,
                                 $logPath = IServer::LOG_PATH,
                                 $accessLogPath = IServer::ACCESS_LOG_PATH);
    
    /**
     * Klassen Destruktor
     *
     * @since Version 0.0.1
     */
    public function __destruct ();
    
    /**
     * Methode zum starten des Servers.
     * Danach lauscht der Server auf dem definierten Port
     * und bindet sich zu definierten IP.
     *
     * @since Version 0.0.1
     */
    public function start ();
    
    /**
     * Methode zum stopen den Server.
     *
     * @since Version 0.0.1
     */
    public function stop ();
    
    /**
     * Methode die das Client Polling ausführt.
     * In einer Schleife aufgerufen,
     * realisiert sie das regelmaessige Socket Polling.
     *
     * @since Version 0.0.1
     */
    public function loop ();
    
    /**
     * Methode mit der, die Request Handler Funktion registriert wird.
     *
     * @since Version 0.0.1
     * @param callback $callback Request Handler Funktion
     */
    public function registerRequestHandler ($callback);
    
    /**
     * Methode mit der registiert wird was als Request Terminierung interpretiert werden soll.
     *
     * @since Version 0.0.1
     * @param mixed $termination Request Termination
     */
    public function setRequestTermination ($termination);
    
    /**
     * Methode mit der, die maximale Anzahl an Request festgelegt wird.
     *
     * @since Version 0.0.2
     * @param integer $maxRequestCount Maximale Anzahl an Request pro Socket
     */
    public function setMaxRequestCount ($maxRequestCount);
    
    /**
     * Methode mit der, das TimeOut des KeepAlive gesetzt wird.
     *
     * @since Version 0.0.2
     * @param integer $timeOut gewuenschtes Timeout des KeepAlive
     */
    public function setKeepAliveTimeOut ($timeOut);
    
    /**
     * Debug Ausgaben anschalten
     *
     * @since Version 0.0.2
     */
    public function enableDebugOutput ();
    
    /**
     * Status des Servers
     *
     * @since Version 0.0.4
     */
    public function serverRunning ();

}

?>